2020-2021 Sunseeker Telemetry and Lighting System
rtc_b_ex1_calendermode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 
66 #include "driverlib.h"
67 
68 volatile Calendar newTime;
69 
70 void main (void)
71 {
72  Calendar currentTime;
73 
74  WDT_A_hold(WDT_A_BASE);
75 
76  //Set P1.0 to output direction
77  GPIO_setAsOutputPin(
78  GPIO_PORT_P1,
79  GPIO_PIN0
80  );
81 
82  /*
83  * Select Port J
84  * Set Pin 4, 5 to input Primary Module Function, LFXT.
85  */
86  GPIO_setAsPeripheralModuleFunctionInputPin(
87  GPIO_PORT_PJ,
88  GPIO_PIN4 + GPIO_PIN5,
89  GPIO_PRIMARY_MODULE_FUNCTION
90  );
91 
92 
93  //Initialize XT1
94  CS_turnOnXT1(CS_XT1_DRIVE_0);
95 
96  //Setup Current Time for Calendar
97  currentTime.Seconds = 0x00;
98  currentTime.Minutes = 0x26;
99  currentTime.Hours = 0x13;
100  currentTime.DayOfWeek = 0x03;
101  currentTime.DayOfMonth = 0x20;
102  currentTime.Month = 0x07;
103  currentTime.Year = 0x2011;
104 
105  //Initialize Calendar Mode of RTC
106  /*
107  * Base Address of the RTC_B
108  * Pass in current time, intialized above
109  * Use BCD as Calendar Register Format
110  */
111  RTC_B_initCalendar(RTC_B_BASE,
112  &currentTime,
113  RTC_B_FORMAT_BCD);
114 
115  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
116  //Note: Does not specify day of the week.
117  RTC_B_configureCalendarAlarmParam param = {0};
118  param.minutesAlarm = 0x00;
119  param.hoursAlarm = 0x17;
120  param.dayOfWeekAlarm = RTC_B_ALARMCONDITION_OFF;
121  param.dayOfMonthAlarm = 0x05;
122  RTC_B_configureCalendarAlarm(RTC_B_BASE, &param);
123 
124  //Specify an interrupt to assert every minute
125  RTC_B_setCalendarEvent(RTC_B_BASE,
126  RTC_B_CALENDAREVENT_MINUTECHANGE);
127 
128  //Enable interrupt for RTC Ready Status, which asserts when the RTC
129  //Calendar registers are ready to read.
130  //Also, enable interrupts for the Calendar alarm and Calendar event.
131 
132  RTC_B_clearInterrupt(RTC_B_BASE,
133  RTCRDYIE + RTCTEVIE + RTCAIE);
134 
135  RTC_B_enableInterrupt(RTC_B_BASE,
136  RTCRDYIE + RTCTEVIE + RTCAIE);
137 
138  //Start RTC Clock
139  RTC_B_startClock(RTC_B_BASE);
140 
141  //Enter LPM3 mode with interrupts enabled
142  __bis_SR_register(LPM0_bits + GIE);
143  __no_operation();
144 }
145 
146 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
147 #pragma vector=RTC_VECTOR
148 __interrupt
149 #elif defined(__GNUC__)
150 __attribute__((interrupt(RTC_VECTOR)))
151 #endif
152 void RTC_B_ISR (void)
153 {
154  switch (__even_in_range(RTCIV,16)){
155  case 0: break; //No interrupts
156  case 2: //RTCRDYIFG
157  //Toggle P1.0 every second
158  GPIO_toggleOutputOnPin(
159  GPIO_PORT_P1,
160  GPIO_PIN0);
161  break;
162  case 4: //RTCEVIFG
163  //Interrupts every minute
164  __no_operation();
165 
166  //Read out New Time a Minute Later BREAKPOINT HERE
167  newTime = RTC_B_getCalendarTime(RTC_B_BASE);
168  break;
169  case 6: //RTCAIFG
170  //Interrupts 5:00pm on 5th day of week
171  __no_operation();
172  break;
173  case 8: break; //RT0PSIFG
174  case 10: break; //RT1PSIFG
175  case 12: break; //Reserved
176  case 14: break; //Reserved
177  case 16: break; //Reserved
178  default: break;
179  }
180 }
181 
MPU_initThreeSegmentsParam param
void main(void)
void RTC_B_ISR(void)
volatile Calendar newTime
__no_operation()